<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 1/29/2015
 * Time: 5:08 PM
 */
namespace app\modules\admin;
use yii;
use yii\web\User;
class AdminModule extends \yii\base\Module {
    public $defaultcontroller = 'default';
    public $homeUrl = 'admin/';
    public function init(){
        parent::init();
        \Yii::configure($this, require(__DIR__ . '/config.php'));
    }
    public function beforeAction($action){
        if(parent::beforeAction($action)){
           $route=$action->controller->id."/".$action->id;
           $allowpage=array(
                'default/login',
                'default/error',
           );
           if(Yii::$app->user->isGuest && !in_array($route,$allowpage)){
                $request=Yii::$app->request->getUrl();
                Yii::$app->getModule('admin')->user->getReturnUrl($request);
               Yii::$app->getModule('admin')->user->loginRequired();
           }else {
                return true;
           }
        }else{
            return false;
        }
    }
}